<template>
  <div class="content">
    <!--获取元素-->
    <h2 ref="title">我是标题</h2>
    <h2 ref="titleRef">setup:我是标题</h2>
    <button ref="btn">获取DOM</button>

    <button @click="getElements">获取元素</button>
    <!--获取组件实例-->
    <ShowInfo ref="showInfoRef" />
  </div>
</template>

<script>
  import { ref, onMounted } from 'vue'
  import ShowInfo from './ShowInfo.vue'

  export default {
    // mounted() {
    //   console.log(this.$refs.title)
    // }
    components: {
      ShowInfo
    },
    setup() {
      const titleRef = ref()
      const showInfoRef = ref()
      // 获取元素:方式一
      onMounted(() => {
        console.log(titleRef.value)
        console.log(showInfoRef.value)
        showInfoRef.value.showInfo()
      })
      // 获取元素:方式二
      function getElements() {
        console.log(titleRef.value)
      }

      return {
        titleRef,
        getElements,
        showInfoRef
      }
    }
  }
</script>

<style scoped>
</style>